import { Map } from "typescript";

export enum ChatMessageSenderReceiverType { sender, receiver }

export enum ChatMessageKind { plainText, picture, video }

class ChatMessage {
  fromNickName?: string = "";
  messageId?:string;
  from?:string;
  toUser?:string;
  message?:string;
  createTime?:string;
  avatarUrl?: string;
  messageSenderReceiverType?:ChatMessageSenderReceiverType  =
      ChatMessageSenderReceiverType.receiver;
  messageKind?:ChatMessageKind  = ChatMessageKind.plainText;

  constructor(props?:{
    messageId?:string,
    toUser:string,
    from:string,
    avatarUrl?:string,
    fromNickName:string,
    messageKind?:ChatMessageKind,
    message:string,
    createTime:string,
    messageSenderReceiverType?:ChatMessageSenderReceiverType,
  }){
    this.messageId = props?.messageId;
    this.toUser = props?.toUser;
    this.from = props?.from;
    this.avatarUrl = props?.avatarUrl;
    this.fromNickName = props?.fromNickName;
    this.messageKind = props?.messageKind;
    this.message = props?.message;
    this.createTime = props?.createTime;
    this.messageSenderReceiverType = props?.messageSenderReceiverType;
  };

  static fromJsonMap(jsonMap:any) {
    return new ChatMessage({
        message:jsonMap["message"],
        toUser:jsonMap["to"],
        from:jsonMap["from"],
        fromNickName:jsonMap["nickname"],
        avatarUrl:jsonMap["avatar"],
        createTime:jsonMap["createTime"],
        messageId:jsonMap["msgId"]
    });
  }

  toParameter? = ()=> {
    return {
        "fromNickName": this.fromNickName,
        "createTime": this.createTime,
        "messageId": this.messageId,
        "avatarUrl": this.avatarUrl,
        "message": this.message,
        "to": this.toUser,
        "from": this.from,
      };
  }

   getAvatarUrl? = ()=> {
    //TODO: replace the value here with dot env file
    return this.avatarUrl ??
        "${AppHelper.shared.getBkDomainName()}/images/2022-12-07T01:54:19.821Z_labi.jpg";
  }

}


export default ChatMessage;